<div class="col-md-8">
<div class="main-content" id="main-content">
	<div class="sub-content">
		<div class="top-header products clearfix">
				<h1>Sale products List</h1>
		</div>
		<div class="user-profile1 col-md-12">
		<form id="formid" method="post" class="form-horizontal" role="form">
		<div class="form-group">
							<label class="control-label col-sm-3">Region:</label>
							<div class="col-sm-9">
				<select id="Country" name="Country" onchange="changeCategory('country')">
					<option value="all">--Select a region--</option>
					<? if(count($this->getallcountries)>0){foreach($this->getallcountries as $getallcountries){?>
						<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='user') {?>
							<option value="<? echo $getallcountries->country_id;?>"><? echo $getallcountries->countryname;?></option>
						<?} else if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='superadmin'){?>
							<option value="<? echo $getallcountries->country_id;?>"><? echo $getallcountries->nicename;?></option>
						<?} else if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='admin'){?>
							<option value="<? echo $getallcountries->country_id;?>"><? echo $getallcountries->countryNicename;?></option>
						<?}?>	
					<?}}?>
				</select>
				</div>
				</div><div class="form-group">
							<label class="control-label col-sm-3">Industry:</label>
							<div class="col-sm-9">
				<select id="Industry" name="Industry" onchange="changeCategory('industry')">
					<option value="all">--Select a industry--</option>
					<? if(count($this->industries)>0){foreach($this->industries as $industries){?>
						<option value="<? echo $industries->industry_id;?>"><? echo $industries->industryname;?></option>
					<?}}?>
				</select>
				</div></div>
				<div class="form-group">
							<label class="control-label col-sm-3">Categories:</label>
							<div class="col-sm-9">
				<select id="category" name="category" onchange="changeCategory('category')">
					<option value="all">--Select category--</option>					
				</select>
				</div></div>
		</form>
				<div class="product_table table-responsive">			
		</div>
	</div></div>
</div> </div>   
<script>
function changeCountry(){
	var country_id=$("#Country").val();
	if(country_id!='all'){
		$.ajax({
			type:	'POST',
			url:   	BASE_PATH+'/products/get-industries',
			data:	{country_id:country_id},
			success: function(data){
				if(data.output=='success'){
					$("#Industry").html(data.industries);
				}
			}
		});
	}else{
		changeCategory('all');
	}
}
function changeIndustry(industry_id){
	if(industry_id!=''){
		var country_id=$("#Country").val();
		$.ajax({
			type:	'POST',
			url:   	BASE_PATH+'/products/get-categories',
			data:	{country_id:country_id,industry_id:industry_id,check:'check'},
			success: function(data){
				if(data.output=='success'){
					$("#category").html(data.categories);
				}
			}
		});
	}else if(industry_id=='all'){
		changeCategory('all');
	}else{
		changeCategory('all');
	}
}
$(function(){
	changeCategory('all');
});
function changeCategory(type){
$('.product_table').html('Please wait loading....');
	if((type=='all') || ($("#Country").val()=='')){
		var cid='all';	
		var inid='all';	
		var catid='all';
		$.ajax({
			type:	'POST',
			dataType:'json',
			url:   	BASE_PATH+'/products/sales-products-ajax',
			data:	{country_id:cid,industry_id:inid,category_id:catid},
			success: function(data){
			$('.product_table').html('<table class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><th>SNO</th><th>Brand Name</th><th>Actual price&nbsp;</th><th>Currency</th><th>Quantity</th><th>Type</th><th>Sales Process</th></tr></thead><tbody></tbody></table>');
			eval(data);
			var oTable = $('#search_results').dataTable( {
					aoColumnDefs: [{bSortable: false,
									aTargets: [ 0 ]
									}],
					"bStateSave": true,
					"bAutoWidth": true,
					"sRowSelect": "multi",
					"sPaginationType": "full_numbers",
					"bProcessing": true,
					"aaData": data,
					"aoColumns": [
						{ "mData": "sno" },
						{ "mData": "brandname" },
						{ "mData": "actualprice" },
						{ "mData": "currency" },
						{ "mData": "quantity" },
						{ "mData": "saleing" },
						{ "mData": "action" }
					] 
				});			
			}
		});	
	}else if(type=='country'){
		var cid=$("#Country").val();
		var inid='all';		
		$.ajax({
			type:	'POST',
			url:   	BASE_PATH+'/products/get-industries',
			data:	{country_id:cid,industry_id:inid,check:'check'},
			success: function(data){
				if(data.output=='success'){				
					$("#Industry").html(data.industries);
					if(cid==''){
						inid='all';
						changeIndustry(inid);
					}else{
						changeIndustry(inid);
					}					
					var catid='all';
					$.ajax({
						type:	'POST',
						dataType:'json',
						url:   	BASE_PATH+'/products/sales-products-ajax',
						data:	{country_id:cid,industry_id:inid,category_id:catid},
						success: function(data){
						$('.product_table').html('<table class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><td>SNO</td><td>Brand Name</td><td width="77px;">Actual price&nbsp;</td><td>Currency</td><td>Quantity</td><td>Type</td><td>Sales Process</td></tr></thead><tbody></tbody></table>');
						eval(data);
						var oTable = $('#search_results').dataTable( {
								aoColumnDefs: [{bSortable: false,
												aTargets: [ 0 ]
												}],
								"bStateSave": true,
								"bAutoWidth": true,
								"sRowSelect": "multi",
								"sPaginationType": "full_numbers",
								"bProcessing": true,
								"aaData": data,
								"aoColumns": [
									{ "mData": "sno" },
									{ "mData": "brandname" },
									{ "mData": "actualprice" },
									{ "mData": "currency" },
									{ "mData": "quantity" },
									{ "mData": "saleing" },
									{ "mData": "action" }
								] 
							});			
						}
					});		
				}
			}
		});	
	}else if(type=='industry'){
		var cid=$("#Country").val();		
		if($("#Industry").val()!=''){
			var inid=$("#Industry").val();
		}else{
			var inid='all';
		}
		var check='check';		
		$.ajax({
			type:	'POST',
			url:   	BASE_PATH+'/products/get-categories',
			data:	{country_id:cid,industry_id:inid,check:'check'},
			success: function(data){
				if(data.output=='success'){					
					$("#category").html(data.categories);
					if(inid=='all'){
						var catid='all';
					}else{
						var catid=$("#category").val();
					}
					$.ajax({
						type:	'POST',
						dataType:'json',
						url:   	BASE_PATH+'/products/sales-products-ajax',
						data:	{country_id:cid,industry_id:inid,category_id:catid},
						success: function(data){
						$('.product_table').html('<table class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><td>SNO</td><td>Brand Name</td><td width="77px;">Actual price&nbsp;</td><td>Currency</td><td>Quantity</td><td>Type</td><td>Sales Process</td></tr></thead><tbody></tbody></table>');
						eval(data);
						var oTable = $('#search_results').dataTable( {
								aoColumnDefs: [{bSortable: false,
												aTargets: [ 0 ]
												}],
								"bStateSave": true,
								"bAutoWidth": true,
								"sRowSelect": "multi",
								"sPaginationType": "full_numbers",
								"bProcessing": true,
								"aaData": data,
								"aoColumns": [
									{ "mData": "sno" },
									{ "mData": "brandname" },
									{ "mData": "actualprice" },
									{ "mData": "currency" },
									{ "mData": "quantity" },
									{ "mData": "saleing" },
									{ "mData": "action" }
								] 
							});			
						}
					});			
				}
			}
		});	
	}else if(type=='category'){
		var cid=$("#Country").val();
		var inid=$("#Industry").val();
		if($("#category").val()!=''){
			var catid=$("#category").val();
		}else{
			var catid='all';
		}		
		$.ajax({
			type:	'POST',
			dataType:'json',
			url:   	BASE_PATH+'/products/sales-products-ajax',
			data:	{country_id:cid,industry_id:inid,category_id:catid},
			success: function(data){
			$('.product_table').html('<table class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><td>SNO</td><td>Brand Name</td><td width="77px;">Actual price&nbsp;</td><td>Currency</td><td>Quantity</td><td>Type</td><td>Sales Process</td></tr></thead><tbody></tbody></table>');
			eval(data);
			var oTable = $('#search_results').dataTable( {
					aoColumnDefs: [{bSortable: false,
									aTargets: [ 0 ]
									}],
					"bStateSave": true,
					"bAutoWidth": true,
					"sRowSelect": "multi",
					"sPaginationType": "full_numbers",
					"bProcessing": true,
					"aaData": data,
					"aoColumns": [
						{ "mData": "sno" },
						{ "mData": "brandname" },
						{ "mData": "actualprice" },
						{ "mData": "currency" },
						{ "mData": "quantity" },
						{ "mData": "saleing" },
						{ "mData": "action" }
					] 
				});			
			}
		});				
	}	
}
</script>























